#ifndef MESSAGES_H
#define MESSAGES_H

  #include "basic.h"
  #include "dataStructures.h"
  #include "functions.h"
  #include "network.h"
  #include "p2p.h"

  //Network Libraries
  #include <sys/types.h>
  #include <sys/socket.h>
  #include <netinet/in.h>
  #include <arpa/inet.h>
  #include <netdb.h>

  // General message handling function. Will call other functions depending
  // message type.
  void handleMessage(unsigned char * message, struct list * requestList, struct addressPort senderInfo);

  // Handles data message types.
  void handleDataMessage(unsigned char * message, struct addressPort senderInfo);

  // Updates the data cache.
  void updateDataCache(unsigned char * filename, unsigned char * content, int fileSize);

  // Updates the content directory.
  void updateContentDirectory(unsigned char * filename, struct addressPort senderInfo);

  // Handles control message types.
  void handleControlMessage(unsigned char * message, struct list * requestList, struct addressPort senderInfo);

  // Handles Listing Message
  void handleListingMessage (unsigned char * message, struct addressPort senderInfo);
	
	// Removes an outstanding request from the list after the data message is resolved.
	void removeOutstandingRequest(unsigned char * filename);
	
	// Message struct for sending messages
	
	// Struct for messages.
	struct aMessage {
		unsigned char messageBuffer[MAX_MSG];
		int messageLength;
	};
	
#endif
